<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk"
      xmlns:v="http://corejsf.com/validator">

    <f:view>
        <f:loadBundle var="text" basename="#{productForm.bundleName}"/>
        <head>
            <title>#{text['productDetail.title']}</title>
            <meta name="heading" content="#{text['productDetail.heading']}"/>
            <meta name="menu" content="CatalogsMenu"/>
        </head>

        <div class="separator"></div>

        <h:form id="productForm">
            <h:inputHidden value="#{productForm.product.id}" id="id"/>

            <h:panelGrid columns="3">

                <h:panelGroup styleClass="buttonBar right">
                    <h:commandButton value="#{text['button.save']}" action="#{productForm.save}" id="save" styleClass="button"/>
                    <c:if test="${not empty productForm.product.id}">
                        <h:commandButton value="#{text['button.delete']}" action="#{productForm.delete}"
                                         id="delete" styleClass="button"/>
                    </c:if>
                    <h:commandButton value="#{text['button.cancel']}" action="cancel" immediate="true"
                                     id="close" styleClass="button"/>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup styleClass="info">
                    <c:choose>
                        <c:when test="${param.from == 'list' or empty productForm.product.id}">
                            <h:outputText value="#{text['productDetail.admin.message']}"/>
                        </c:when>
                        <c:otherwise><h:outputText value="#{text['productDetail.message']}"/></c:otherwise>
                    </c:choose>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:outputLabel for="description" value="#{text['product.description']}" styleClass="desc"/>
                <t:message for="description" styleClass="fieldError"/>
                <h:inputText value="#{productForm.product.description}" id="description" styleClass="text large" required="true"/>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="unitMeasure" value="#{text['product.unitMeasure']}"/>
                            <h:selectOneMenu value="#{productForm.product.unitMeasure}" id="unitMeasure" required="true" styleClass="select">
                                <t:selectItems value="#{productForm.unitMeasures}" var="unitMeasure" itemLabel="#{unitMeasure.description}" itemValue="#{unitMeasure}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <t:message for="unitMeasure" styleClass="fieldError"/>
                            <v:commonsValidator client="true" type="required" arg="#{text['product.unitMeasure']}"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="measure" value="#{text['product.measure']}"/>
                            <h:inputText styleClass="text medium" id="measure" value="#{productForm.product.measure}" required="true"/>
                            <t:message for="measure" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="code" value="#{text['product.code']}"/>
                            <h:inputText styleClass="text medium" id="code" value="#{productForm.product.code}" maxlength="100" required="true"/>
                            <t:message for="code" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="precio" value="#{text['product.price']}"/>
                            <h:inputText styleClass="text medium" id="precio" value="#{productForm.product.price}" required="true">
                                <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                            </h:inputText>
                            <t:message for="precio" styleClass="fieldError"/>
                            <t:htmlTag value="p"><h:outputLabel for="precio" value="#{text['product.currency']}"/></t:htmlTag>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="minPrice" value="#{text['product.minPrice']}"/>
                            <h:inputText styleClass="text medium" id="minPrice" value="#{productForm.product.minPrice}" required="true">
                                <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                            </h:inputText>
                            <t:message for="minPrice" styleClass="fieldError"/>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="maxPrice" value="#{text['product.maxPrice']}"/>
                            <h:inputText styleClass="text medium" id="maxPrice" value="#{productForm.product.maxPrice}" required="true">
                                <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                            </h:inputText>
                            <t:message for="maxPrice" styleClass="fieldError"/>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>

                <h:panelGroup>
                    <div>
                        <div class="left">
                            <h:outputLabel styleClass="desc" for="maxPrice" value="#{text['product.resolution']}"/>
                            <h:selectOneMenu value="#{productForm.product.resolution}" id="resolution" required="true" styleClass="select">
                                <t:selectItems value="#{productForm.resolutions}" var="resolution" itemLabel="#{resolution.description}" itemValue="#{resolution}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <t:message for="resolution" styleClass="fieldError"/>
                            <v:commonsValidator client="true" type="required" arg="#{text['product.resolution']}"/>
                            <t:htmlTag value="p"><h:outputLabel for="resolution" value="#{text['product.resolution']}"/></t:htmlTag>
                        </div>
                        <div>
                            <h:outputLabel styleClass="desc" for="maxPrice" value="#{text['product.workType']}"/>
                            <h:selectOneMenu value="#{productForm.product.workType}" id="workType" required="true" styleClass="select">
                                <t:selectItems value="#{productForm.workTypes}" var="workType" itemLabel="#{workType.description}" itemValue="#{workType}"/>
                                <f:converter converterId="objconverter"/>
                            </h:selectOneMenu>
                            <t:message for="workType" styleClass="fieldError"/>
                            <v:commonsValidator client="true" type="required" arg="#{text['product.workType']}"/>
                            <t:htmlTag value="p"><h:outputLabel for="workType" value="#{text['product.workType']}"/></t:htmlTag>
                        </div>
                    </div>
                </h:panelGroup>
                <h:outputText/><h:outputText/>
            </h:panelGrid>
        </h:form>

        <script type="text/javascript">
            Form.focusFirstElement($('productForm'));
            highlightFormElements();
        </script>
    </f:view>
</html>